package com.example.blog.advice;

import com.example.blog.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler
    public Result handle(NoResourceFoundException e){
        log.error("文件不存在:{}", e.getResourcePath());
        return Result.fail("内部错误, 请联系管理员2");
    }
    @ExceptionHandler
    public Result handle(UserNotFoundException e) {
        log.warn("登录失败: {}", e.getMessage());
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler
    public Result handle(PasswordIncorrectException e) {
        log.warn("登录失败: {}", e.getMessage());
        return Result.fail(e.getMessage());
    }
}
